import 'package:flutter/material.dart';
import 'package:love_app/common/su.dart';
import 'package:love_app/test/bottom_test.dart';

// main函数走测试
class MainTest extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return NewBottomAppbar();
  }
}



/// 有没有可能是因为嵌套的原因
class NewBottomAppbar extends StatefulWidget {
  @override
  _NewBottomAppbarState createState() => _NewBottomAppbarState();
}

// 暂时不使用自定义导航栏，用flutter自带的
class _NewBottomAppbarState extends State<NewBottomAppbar> {
  // 导航栏点击的页面
  final List<Widget> _pages = [
    // HomePage(), // 主页
    // CommunityPage(), // 社区
    // MinePage(), // 个人
    BottomTest(),
    BottomPage1(),
    BottomPage2(),
    
  ];
  int _currentIndex; // 维护一个下标
  List<BottomNavigationBarItem> _items;

  @override
  void initState() {
    super.initState();
    _currentIndex = 0;
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _items = [
      _myBar(Icons.android, "测试"),
      _myBar(Icons.android, "测试"),
      _myBar(Icons.android, "测试"),
    ];
  }

  @override
  Widget build(BuildContext context) {
    Su.suPrints("NewBottomAppbar触发了build");
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        items: _items,
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        onTap: onTabTapped,
        selectedItemColor: Colors.black,
        unselectedItemColor: Color.fromRGBO(221, 221, 221, 1),
        elevation: 0,
        backgroundColor: Colors.white,
      ),
      body: IndexedStack(
        children: _pages,
        index: _currentIndex,
      ),
    );
  }

  // 切换indexedSta
  void onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  BottomNavigationBarItem _myBar(
      IconData iconData, String title) {
    return BottomNavigationBarItem(
      icon: Icon(
        iconData,
      ),
      title: Text(title),
      backgroundColor: Colors.white,
    );
  }
}
